package com.shop.admin.controller.course;

import com.shop.admin.aop.Log;
import com.shop.admin.service.ICourseAudienceService;
import com.shop.admin.validate.commons.IdValidate;
import com.shop.admin.validate.commons.PageValidate;
import com.shop.admin.validate.course.CourseAudienceCreateValidate;
import com.shop.admin.validate.course.CourseAudienceSearchValidate;
import com.shop.common.core.AjaxResult;
import com.shop.common.core.PageResult;
import com.shop.common.entity.course.CourseAudience;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("${app.api-prefix}/course/audience")
@Api(tags = "课程观众管理")
public class CourseAudienceController {

    @Resource
    ICourseAudienceService  iCourseAudienceService;

    @Log(title = "课程观众列表")
    @GetMapping("/list")
    @ApiOperation("课程观众列表")
    public AjaxResult<PageResult<CourseAudience>> list(@Validated PageValidate pageValidate, CourseAudienceSearchValidate searchValidate) {
        return AjaxResult.success(iCourseAudienceService.list(pageValidate, searchValidate));
    }

    @Log(title = "课程观众新增")
    @PostMapping("/add")
    @ApiOperation("课程观众新增")
    public AjaxResult<Object> add(@Validated @RequestBody CourseAudienceCreateValidate createValidate) {
        iCourseAudienceService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "课程观众删除")
    @PostMapping("/del")
    @ApiOperation("课程观众删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iCourseAudienceService.del(idValidate.getId());
        return AjaxResult.success();
    }
}
